home *** CD-ROM | disk | FTP | other *** search
/ ASME's Mechanical Engine…ing Toolkit 1997 December / ASME's Mechanical Engineering Toolkit 1997 December.iso / c_lang / varinc.lzh / PAGE204A.C < prev    next >
Text File  |  1979-11-30  |  553b  |  14 lines

  1. /* Count the number of lines and characters in stdin(). */
  2. #include <stdio.h>
  3.  
  4. main()
  5.    {
  6.    int input;                               /* input returned from getchar() */
  7.    long chars, lines;                   /* counters for lines and characters */
  8.  
  9.    for (lines = chars = 0; (input = getchar()) != EOF; ++chars)
  10.       if (input == '\n')                                   /* End of a line? */
  11.          ++lines;                          /* Yes. Increment count of lines. */
  12.    printf("%ld lines, %ld characters\n", lines, chars);
  13.    }  
  14.